Jextract - Java Treasures from Native Code Gems

When developing a Java application, there can be use cases when you need access to system-level APIs and libraries written in other programming languages ( C, OpenGL, Tensorflow, Rust, Python, etc.). Project Panama is designed to facilitate access to native libraries, particularly those developed in C/C++, from Java code.

Interaction between the JVM and the “foreign” (non-Java) APIs has been made simpler with the Foreign Function and Memory API (FFM API). The FFM API became a final feature in JDK 22, and it comes with a little gem - the jextract tool - that can automate obtaining access to native code. jextract parses header files (.h) of native libraries and generates Java code, named bindings that use the FFM API internally.

This talk will walk you through working with jextract and how to directly use its output as a Java model of the native libraries you are interested in.

Recorded at Devoxx Belgium 2024.